﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Repository.Entities;

namespace LawProject.Models
{
    public class NguyenCustomPage
    {
        public int SoRecordMax { get; set; }
        private int tongtrang;
        public int TongTrang
        {
            get
            {
                return this.tongtrang;
            }
            set
            {
                this.tongtrang = value;
                if (value < SoTrangHienThi)
                    SoTrangHienThi = value;
            }
        }
        private int sotranghienthi;
        public int SoTrangHienThi { get; set; }
        public int TrangHienTai { get; set; }
        public int SoRecord { get; set; }
        public string StringDau { get; set; }
        public string StringCuoi { get; set; }
        public string StringNext {get; set; }
        public string StringPre {get; set; }        
        public List<int> ListTrang { get; set; }
        public List<ViewBaseTinMoi> PageContent { get; set; }
        public NguyenCustomPage()
        {
            TongTrang = 1;
            SoTrangHienThi = 1;
            StringDau = "Đầu";
            StringCuoi = "Cuối";
            StringNext = ">";
            StringPre = "<";
            TrangHienTai = 1;
            ListTrang = new List<int>();
            PageContent = new List<ViewBaseTinMoi>();
            ListTrang.Add(1);
        }
        public NguyenCustomPage(int tongtrang, int sotrang, string stringdau, string stringcuoi, string stringnext, string stringpre, int tranghientai)
        {
            this.TongTrang = tongtrang;
            this.SoTrangHienThi = sotrang;
            this.StringDau = stringdau;
            this.StringCuoi = stringcuoi;
            this.StringNext = stringnext;
            this.StringPre = stringpre;
            this.TrangHienTai = tranghientai;
        }

        private void XuLyListTrang(int currentPage, int requestPage)
        {
            int beginPage = 1;
            if (requestPage < currentPage)
            {
                beginPage = requestPage;
            }
            else
            {
                if (requestPage > currentPage + this.SoTrangHienThi - 1)
                {
                    beginPage = requestPage - this.SoTrangHienThi + 1;
                }
                else
                {
                    beginPage = currentPage;
                }
            }
            this.ListTrang = new List<int>();
            for (int i = 0; i < SoTrangHienThi; i++)
            {
                ListTrang.Add(beginPage++);
            }
            TrangHienTai = requestPage;
            
        }

        public void XuLyPhanTrang(List<ViewBaseTinMoi> recordData, int currentPage, int requestPage)
        {
            this.XuLyListTrang(currentPage, requestPage);
            PageContent = recordData;
        }
    }
}